﻿Public Class frmHelp

    Private Sub frmHelp_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.WebBrowser1.Navigate(HtmlFormatter.getAppPathForHtml & "help/index.html")
    End Sub
End Class

Public Class HtmlFormatter

    Public Shared ReadOnly FILE_URL_PREFIX As String = "file://"
    Public Shared ReadOnly PATH_SEPARATOR As String = "/"

    Public Shared Function ReplaceImagePath(ByVal html As [String], ByVal path As [String]) As [String]
        Return html.Replace("file://ApplicationPath/", path)
    End Function

    ''' <summary> 
    ''' Replaces URLs matching file://ApplicationPath/... with Executable Path 
    ''' </summary> 
    ''' <param name="html"></param> 
    ''' <returns></returns> 
    Public Shared Function ReplaceImagePathAuto(ByVal html As [String]) As [String]

        Return ReplaceImagePath(html, HtmlFormatter.getAppPathForHtml())

    End Function

    Public Shared Function getAppPathForHtml() As String
        Dim executableName As [String] = System.Windows.Forms.Application.ExecutablePath
        Dim executableFileInfo As New System.IO.FileInfo(executableName)
        Dim executableDirectoryName As [String] = executableFileInfo.DirectoryName
        Return HtmlFormatter.FILE_URL_PREFIX & executableDirectoryName & HtmlFormatter.PATH_SEPARATOR

    End Function
End Class
